#include <iostream>
#include <unordered_map>
#include <vector>
using namespace std;

int main() {
    vector<int> tot(128, 0);
    auto prev = tot;
    int n;
    cin >> n;
    string s;
    cin >> s;
    for (auto it : s)
        tot[it - 'a']++;
    long long res = 0;
    for (int i = 0; i < s.size(); i++)
    {
        char t = s[i] - 'a';
        long long back = tot[t] - prev[t] - 1;
        int front = i - prev[t];
        res += back * front;
        prev[t]++;
    }
    cout << res << endl;
    return 0;
}